package com.example.feed;

import android.app.Application;

import androidx.annotation.NonNull;

import com.x.uikit.router.IXRouteHandler;
import com.x.uikit.router.XRoute;
import com.x.uikit.router.XRouteManager;

public class FeedInitializer {
    private Application sApplication;
    private boolean sInit = false;
    private static FeedInitializer sInstance = new FeedInitializer();
    private XRouteManager mManager;

    public static FeedInitializer get() {
        return sInstance;
    }

    private FeedInitializer() {

    }

    public void init(Application application) {
        if (sInit) {
            return;
        }
        sInit = true;
        sApplication = application;
        mManager = new XRouteManager(application.getApplicationContext());
        mManager.registerRouteHandler(new IXRouteHandler() {
            @Override
            public boolean needIntercept(@NonNull XRoute route) {
                return FeedPageRouteList.hasPath(route);
            }

            @Override
            public void onHandle(@NonNull XRoute route) {

                FeedPageRouteList.navigate(route);
            }
        });
    }
}
